Title: SQL W3S (By-BKK) / 042 Comments
Tags: Obsidian_to_Anki

Q: What is the primary purpose of comments in SQL?
A: To explain sections of SQL statements or prevent execution of SQL statements

Q: Comments are supported in Microsoft Access databases. True/False
A: False

Q: How do you start a single-line comment in SQL?
A: With two hyphens: --

Q: Which part of a SQL statement is ignored when a single-line comment is added?
A: The text between -- and the end of the line

Q: Show an example of a single-line comment as explanation in SQL.
A: -- Select all:
SELECT *
FROM Customers;

Q: What does the following do in SQL?
SELECT * FROM Customers -- WHERE City='Berlin';
A: Ignores the WHERE part due to the comment; selects all customers

Q: How do you ignore an entire SQL statement using a single-line comment?
A: Put -- before the statement

Q: Give an example of ignoring a statement with a single-line comment.
A: -- SELECT * FROM Customers;
SELECT * FROM Products;

Q: How do you start and end a multi-line comment in SQL?
A: Start with /* and end with */

Q: What happens to the text inside /* and */in SQL?
A: It is ignored by SQL; not executed

Q: Show an example of a multi-line comment used for explanation.
A: /*Select all the columns
of all the records
in the Customers table:*/
SELECT *
FROM Customers;

Q: How do you use a multi-line comment to ignore several SQL statements?
A: Put all statements between /* and */

Q: Give an example of ignoring multiple statements with a multi-line comment.
A: /*SELECT * FROM Customers;
SELECT * FROM Products;
SELECT * FROM Orders;
SELECT * FROM Categories;*/
SELECT *
FROM Suppliers;

Q: Can you use /* and */ within a line to ignore part of a SQL statement? True/False
A: True

Q: How do you ignore just a column in a SELECT statement using a comment?
A: /column_name/ in the SELECT statement

Q: Show an example of ignoring a column in SELECT using a comment.
A: SELECT CustomerName, /City,/ Country
FROM Customers;

Q: How do you ignore conditions within a WHERE clause using a comment?
A: Enclose the unwanted conditions within /* and */

Q: Give an example of ignoring conditions in WHERE clause.
A: SELECT *
FROM Customers
WHERE (CustomerName LIKE 'L%' OR CustomerName LIKE 'R%'
/*OR CustomerName LIKE 'S%'
OR CustomerName LIKE 'T%'*/
OR CustomerName LIKE 'W%')
AND Country='USA'
ORDER BY CustomerName;

Q: To explain SQL code or prevent execution, use comments.
A: True

Q: You can use single-line comments in SQL with --. Reverse
A: How do you add a single-line comment in SQL?

Q: Text between /* and */ is ignored by SQL. Reverse
A: What does SQL do with text inside multi-line comments?

Q: Single-line comments and multi-line comments can both be used to ignore part of a SQL statement. True/False
A: True